package ex;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class Werewolfkill {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        System.out.println("几人玩？");
        int num=sc.nextInt();
        //
            switch (num) {
                case 12:
                    String[] cards = reSuffer(num);
                    if (cards[cards.length - 1] != "盗贼" && cards[cards.length - 2] != "盗贼" &&
                            cards[cards.length - 3] != "盗贼") {
                        int j = notLang(cards);
                        //System.out.println(j);
                        if (j < 2) {
                            outPut(cards);
                        }
                    }
                    break;
                case 13:
                    String[] cards3 = reSuffer(num);
                    if (cards3[cards3.length - 1] != "盗贼" && cards3[cards3.length - 2] != "盗贼" &&
                            cards3[cards3.length - 3] != "盗贼") {
                        int j = notLang(cards3);
                        //System.out.println(j);
                        if (j < 2) {
                            outPut(cards3);
                        }
                    }
                    break;
                case 14:
                    String[] cards4 = reSuffer(num);
                    if (cards4[cards4.length - 1] != "盗贼" && cards4[cards4.length - 2] != "盗贼" &&
                            cards4[cards4.length - 3] != "盗贼") {
                        int j = notLang(cards4);
                        //System.out.println(j);
                        if (j < 2) {
                            outPut(cards4);
                        }
                    }
                    break;
                case 15:
                    String[] cards5 = reSuffer(num);
                    if (cards5[cards5.length - 1] != "盗贼" && cards5[cards5.length - 2] != "盗贼" &&
                            cards5[cards5.length - 3] != "盗贼") {
                        int j = notLang(cards5);
                        //System.out.println(j);
                        if (j < 2) {
                            outPut(cards5);
                        }
                    }
                    break;
                case 16:
                    String[] cards6 = reSuffer(num);
                    if (cards6[cards6.length - 1] != "盗贼" && cards6[cards6.length - 2] != "盗贼" &&
                            cards6[cards6.length - 3] != "盗贼") {
                        int j = notLang(cards6);
                        //System.out.println(j);
                        if (j < 2) {
                            outPut(cards6);
                        }
                    }
                    break;
                case 17:
                    String[] cards7 = reSuffer(num);
                    if (cards7[cards7.length - 1] != "盗贼" && cards7[cards7.length - 2] != "盗贼" &&
                            cards7[cards7.length - 3] != "盗贼") {
                        int j = notLang(cards7);
                        //System.out.println(j);
                        if (j < 2) {
                            outPut(cards7);
                        }
                    }
                    break;
                case 18:
                    String[] cards8 = reSuffer(num);
                    if (cards8[cards8.length - 1] != "盗贼" && cards8[cards8.length - 2] != "盗贼" &&
                            cards8[cards8.length - 3] != "盗贼") {
                        int j = notLang(cards8);
                        //System.out.println(j);
                        if (j < 2) {
                            outPut(cards8);
                        }
                    }
                    break;
                default:
                    System.out.println("人数不符");
            }
        }
    //洗牌
    private static String[] reSuffer(int num) {
        //生成随机数
        Random r = new Random();
        String[] card = {"盗贼","村民","村民","村民","村民","狼人","狼人","狼人","狼人","预言家","女巫","丘比特","守护","猎人", "村长",
                "村民","替罪羊","狼人","村民","村民","吹笛者",};
        String[] cards = Arrays.copyOf(card,num+3);
        for(int i=0;i<=4*cards.length;i++){
            int rd = r.nextInt(cards.length-1);
            String temp=cards[rd];
            cards[rd]=cards[0];
            cards[0]=temp;
        }
        return cards;
    }
    //输出
    public static int outPut(String[] cards){
        //洗碗后的所有牌
        //System.out.println(Arrays.toString(cards) + "\n");
        String[] cards1=Arrays.copyOf(cards,cards.length-3);
        System.out.println("手牌为:");
        for (int i=0;i<=cards1.length-1;i++){
            System.out.print("0" + (i+1)+cards1[i] + "\t");
        }
        System.out.println();
        String[] cards2=new String[3];
        System.arraycopy(cards,cards.length-3,cards2,0,3);
        System.out.println("底牌为:");
        for (int i=0;i<=2;i++){
            System.out.print("0" +(i+1)+ cards2[i] + "\t");
        }
        return 1;
    }
    //判断底牌至多有一个狼人
    public static int notLang(String[] cards){
        int j=0;
        for(int i=1;i<=3;i++){
            if (cards[cards.length-i]=="狼人"){
                j++;
            }
        }
        return j;
    }
}
